<?php
// just require TCPDF instead of FPDF

//define('FPDF_FONTPATH','font/');
require_once('TCPDF/tcpdf.php');
require_once('FPDI/fpdi.php');

class PDF extends FPDI {
    /**
     * "Remembers" the template id of the imported page
     */
    var $_tplIdx;
    
    /**
     * include a background template for every page
     */
    function Header() {
        if (is_null($this->_tplIdx)) {
            $this->setSourceFile('../pdf_form/doc1.pdf');
            $this->_tplIdx = $this->importPage(1);
        }
        $this->useTemplate($this->_tplIdx);

		/*
		//$this->AddFont('THSarabunNew','','THSarabunNew.php');
        //$this->SetFont('THSarabunNew', '', 9);
        $this->SetTextColor(255);
        $this->SetXY(60.5, 24.8);
        $this->Cell(0, 8.6, "TCPDF and FPDI");
		*/
    }
    
    function Footer() {}
}

// initiate PDF
$pdf = new PDF();
$pdf->SetMargins(PDF_MARGIN_LEFT, 40, PDF_MARGIN_RIGHT);
$pdf->SetAutoPageBreak(true, 40);
$pdf->setFontSubsetting(false);

// add a page
$pdf->AddPage();

// get esternal file content
//$utf8text = file_get_contents("cache/utf8test.txt", true);
$utf8text="test";
//$pdf->AddFont('THSarabunNew','','THSarabunNew.php');
//$pdf->SetFont("freeserif", "", 12);
$pdf->SetFont('thsarabun','',35);
// now write some text above the imported page
$pdf->Write(5, $utf8text);


$pdf->Output('newbill.pdf', 'I');
